import csv

import requests
import json



header = {
    'Cookie':'TrainingPlatform-sid=s%3Az6XvdFTP1LUq65jWx-qh4hfhHoJ5r6zs.ItR5gMeubEGZdjGMu8Qf3MwZsqIe%2BPtKna9ExhZfnig; local-state={%22_id%22:%225f02f2349fd8b6fa72e727cf%22%2C%22username%22:%22admin%22%2C%22email%22:%22admin@forensix.cn%22%2C%22roles%22:[%22admin%22]%2C%22avatar%22:%22http://account-test.forensix.cn/avatars/avatar.5a4e0bc20de70d51abff9cc8.4900.png%22%2C%22isReset%22:false%2C%22isModifyPersonal%22:true}; XSRF-TOKEN=Tl8P7HfQ-yGqV6nxKhrPWqVHjahCLSKRm4wU',
    'X-XSRF-TOKEN':'Tl8P7HfQ-yGqV6nxKhrPWqVHjahCLSKRm4wU'
}

# response = requests.request("GET", "http://172.16.60.14/testPaper/detail?_id=5fbc9a24ba155a5b4e87ff03&forTraining=true", headers = header)
response = requests.request("GET", "http://172.16.60.14/testPaper/detail?_id=5fcdfeb4d6d112f23984d6b8", headers = header)
# print(response.json()['sections'])

with open("answer.csv", 'w', newline='') as a:
    csv_writer = csv.writer(a)
    csv_writer.writerow(['正确答案'])

    for i in response.json()['sections']:
        for x in i['questions']:
            csv_writer.writerow([x['answer']])